﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Location.aspx.cs" Inherits="WebForms_Location" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
     <section class="featured">
        <div class="content-wrapper" dir="rtl">
           موقعیت مکانی
        </div>
    </section>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <div dir="rtl" style="width: 10%; float: right">&nbsp;</div>
    <div dir="rtl" style="width: 30%; float: right">
        <asp:LinkButton ID="ClearSelectionLinkButton" runat="server" OnClick="ClearSelectionLinkButton_Click">هیچکدام</asp:LinkButton>
        <br />
        <asp:TreeView ID="LocationTreeView" runat="server" CollapseImageToolTip="عدم نمایش زیر مجموعه های {0}"
            ExpandImageToolTip="نمایش زیر مجموعه های {0}" NodeIndent="7" SkinID="LocationTreeView"
            Width="98%" OnSelectedNodeChanged="LocationTreeView_SelectedNodeChanged">
        </asp:TreeView>
    </div>
    <br />
    <div dir="rtl" style="width: 10%; float: right">&nbsp;</div>
    <div dir="rtl" style="width: 50%; float: right">
        <asp:MultiView ID="PageMultiView" runat="server" ActiveViewIndex="0">
            <asp:View ID="ParentView" runat="server">
                <asp:FormView ID="LocationFormView" runat="server" DataKeyNames="PkLocationID" DataSourceID="LocationObjectDataSource"
                    DefaultMode="Insert" OnItemDeleted="LocationFormView_ItemDeleted" Width="100%">
                    <EditItemTemplate>
                        عنوان موقعیت:
                                <asp:TextBox ID="LocationNameTextBox" runat="server" Text='<%# Bind("LocationName") %>' />
                         <asp:RequiredFieldValidator ID="LocationNameRequiredFieldValidator" runat="server" ControlToValidate="LocationNameTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <br />
                        <asp:HiddenField ID="ParentIDHiddenField" runat="server" Value='<%# Bind("FkParentID") %>' />
                        <asp:HiddenField ID="TypeHiddenField" runat="server" Value='<%# Bind("Type") %>' />
                        <div style="float: left; padding: 10px;">
                            <asp:LinkButton ID="AddChildLinkButton" runat="server" Text="درج فرزند" OnPreRender="AddChildLinkButton_PreRender" OnClick="AddChildLinkButton_Click" 
                                ValidationGroup="Update" CssClass="button" />
                            <asp:LinkButton ID="DeleteLinkButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="button"
                                OnClientClick="if (!confirm('آيا از حذف مطمئن هستيد؟')) return false;" Text="حذف" />
                            <asp:LinkButton ID="UpdateLinkButton" runat="server" CommandName="Update"
                                ValidationGroup="Update" OnClientClick="if (!confirm('آيا از اعمال تغییرات مطمئن هستيد؟')) return false;" Text="ویرایش" CssClass="button" OnClick="UpdateLinkButton_Click" />
                            <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                        </div>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:Label ID="ParentLabel" runat="server" OnPreRender="ParentLabel_PreRender" Width="250px"></asp:Label>
                        <br />
                        عنوان موقعیت:
                                <asp:TextBox ID="LocationNameTextBox" runat="server" Text='<%# Bind("LocationName") %>' />
                        <asp:RequiredFieldValidator ID="LocationNameRequiredFieldValidator" runat="server" ControlToValidate="LocationNameTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <br />
                        <asp:HiddenField ID="ParentIDHiddenField" runat="server" Value='<%# Bind("FkParentID") %>' />
                        <asp:HiddenField ID="TypeHiddenField" runat="server" Value='<%# Bind("Type") %>' />

                        <div style="float: left; padding: 10px;">
                            <asp:LinkButton ID="InsertLinkButton" runat="server" CommandName="Insert" Text="ایجاد" CssClass="button"
                                ValidationGroup="Insert" OnClick="InsertLinkButton_Click" />
                            <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                        </div>
                    </InsertItemTemplate>
                </asp:FormView>
            </asp:View>
        </asp:MultiView>
    </div>
    <asp:ObjectDataSource ID="LocationObjectDataSource" runat="server" SelectMethod="Select" TypeName="Location" DeleteMethod="Delete"
        InsertMethod="Insert" UpdateMethod="Update" OnDeleted="LocationObjectDataSource_Command" OnInserted="LocationObjectDataSource_Command" OnUpdated="LocationObjectDataSource_Command">
        <DeleteParameters>
            <asp:ControlParameter ControlID="LocationFormView" Name="PkLocationID" PropertyName="SelectedValue" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>           
            <asp:Parameter Name="LocationName" Type="String"></asp:Parameter>
            <asp:ControlParameter ControlID="ParentIDHiddenField" Name="FkParentID" PropertyName="Value" Type="Int32" />
            <asp:ControlParameter ControlID="TypeHiddenField" Name="Type" PropertyName="Value" Type="Byte" />
        </InsertParameters>
        <SelectParameters>
             <asp:ControlParameter ControlID="LocationTreeView" Name="PkLocationID" PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:ControlParameter ControlID="LocationFormView" Name="PkLocationID" PropertyName="SelectedValue" Type="Int32" />
            <asp:Parameter Name="LocationName" Type="String"></asp:Parameter>
            <asp:ControlParameter ControlID="ParentIDHiddenField" Name="FkParentID" PropertyName="Value" Type="Int32" />
            <asp:ControlParameter ControlID="TypeHiddenField" Name="Type" PropertyName="Value" Type="Byte" />
        </UpdateParameters>
    </asp:ObjectDataSource>
    <asp:HiddenField ID="ParentIDHiddenField" runat="server"/>
    <asp:HiddenField ID="TypeHiddenField" runat="server"/>
</asp:Content>

